%Computation of signal and noise power in E fields
% not tested
% Reference :Gamble, Goubau & Clarke 1978. Error analysis for rr mt, Geophysics 44 959-968
% Latest date 19.4.3

function[s,n] = esig(SPM,ProcDef,flag);

A = size(SPM);
k = length(A);
j = sqrt(-1);
if flag == 'Ex',
   x = 3;
   y = 1;
elseif flag == 'Ey',
   x = 2;
   y = 4;
else,
   fprintf('pcoh-> Allowed flags Ex  Ey\n');
   c=999;
   return;
end;


if k == 2,
   data(:,:)=SPM;
   t = tf(data,ProcDef);
   c = esgns(t(x),t(y),data,flag);
   s=c(1);n=c(2);
elseif k == 3,
   t = tf(SPM,ProcDef);
   for i = 1:A(1),
      data(:,:) = SPM(i,:,:);
      c(i,:) = esgns(t(i,x),t(i,y),data,flag);
   end;
   s=c(:,1);
   n=c(:,2);
elseif k==4,
   for ii = 1:A(2),
      t = tf(SPM(:,ii,:,:),ProcDef);
      for i = 1:A(1),
         data(:,:) = SPM(i,ii,:,:);
         c = esgns(t(i,x),t(i,y),data,flag);
         s(i,ii)=c(1);
         n(i,ii)=c(2);
      end;
   end;
 end;


         
      

